package com.bravo.mvpkotlin.data.source

import com.bravo.mvpkotlin.data.BASE_URL
import com.bravo.mvpkotlin.data.DataManager
import com.bravo.mvpkotlin.data.source.api.GithubService
import com.bravo.mvpkotlin.data.source.local.Local
import com.bravo.mvpkotlin.data.source.local.LocalDataSource
import com.bravo.mvpkotlin.data.source.romate.Remote
import com.bravo.mvpkotlin.data.source.romate.RemoteDataSource
import dagger.Module
import dagger.Provides
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory

/**
 * Created by Administrator on 2017/6/22.
 */

@Module
class DataSourceModule {

    @Provides
    fun provideGithubService(): GithubService {
        return Retrofit.Builder()
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .baseUrl(BASE_URL)
                .build()
                .create(GithubService::class.java)
    }

    @Provides
    @Remote
    fun provideRemote(githubService: GithubService): RemoteDataSource {
        return RemoteDataSource(githubService)
    }

    @Provides
    @Local
    fun provideLocal(): LocalDataSource {
        return LocalDataSource()
    }

    @Provides
    fun provideDataManager(@Remote remote: RemoteDataSource,@Local  local: LocalDataSource): DataManager {
        return DataManager(remote, local)
    }
}